package edu.tyut.game.logic.dao

import edu.tyut.game.GameApplication
import edu.tyut.game.logic.model.User
import edu.tyut.game.utils.LogUtils

object GameDB {

    private const val tag = "GameDB"
    private val database = GameDataBase.getDatabase(GameApplication.context)
    private val userDao = database.userDao()

    // ========================== Database ==================================
    /**
     * 在本地数据库查询
     */
    fun existUser(user: User): User? {
        LogUtils.d(tag, "existUser插入数据成功")
        return userDao.existUser(user.username, user.password)
    }
    /**
     * 注册到本地数据库
     */
    fun registerDB(user: User){
        LogUtils.d(tag, "registerDB插入数据成功")
        userDao.insertAll(user)
    }

    fun updatePassword(user: User){
        LogUtils.d(tag, "本地密码更新成功！")
        userDao.updatePassword(user.username, user.password)
    }
    fun updateHeadIcon(uid: Int, avatarPath: String){
        GameApplication.loginUser?.avatarPath = avatarPath
        LogUtils.d(tag, "头像更新成功!")
        userDao.updateHeadIcon(uid, avatarPath)
    }
}



